Private Sub Workbook_BeforeClose(Cancel As Boolean)

    Dim  As String
    Dim ϸ As String

    With ThisWorkbook

        If Not .Saved Then
    
            If .FileFormat = 51 Then
    
                Application.DisplayAlerts = False
                    
                     = .FullName
                    
                    ϸ = Left(.Name, Len(.Name) - Len(".xlsx"))
                    .SaveAs .Path & "\" & ϸ & ".xlsm", 52
                    
                    Kill 
                
                Application.DisplayAlerts = True
    
            Else
    
                ThisWorkbook.Save
    
            End If
        
        End If
        
    End With
    
End Sub